home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / ops5c.zip / WALTZ.OPS < prev   
Text File  |  1988-12-09  |  12KB  |  403 lines

  1.                                                 ;and the RHS actions that
  2.                                                 ;are user defined
  3.  
  4.  
  5. ;Our WM elements.  Lines have the lable line followed by the 2 points
  6. ;defining the line.  Edges are like lines accept that they can be labeled,
  7. ;permanently labelled and plotted.  Junctions are defined by 4 points.  The
  8. ;basepoint is where the 3 (2) lines intersect.  The points p1, p2, p3 are the
  9. ;other endpoints of the lines at this junction
  10.  
  11. (literalize stage value)
  12. (literalize line p1 p2)
  13. (literalize edge p1 p2 joined label plotted)
  14. (literalize junction p1 p2 p3 base_point type)
  15.  
  16. ;The Waltz Algorithm using OPS5 Production System Interpreter
  17. ;This is our production memory
  18.  
  19. ;Our starting production.  It checks to see if the start flag is in WM,
  20. ;and if it is, it deletes it, and clears the screen
  21. (p begin
  22.     (stage ^value start)
  23.     -->
  24. ;    (write clr)
  25.     (make line ^p1 0122 ^p2 0107)
  26.     (make line ^p1 0107 ^p2 2207)
  27.     (make line ^p1 2207 ^p2 3204)
  28.     (make line ^p1 3204 ^p2 6404)
  29.     (make line ^p1 2216 ^p2 2207)
  30.     (make line ^p1 3213 ^p2 3204)
  31.     (make line ^p1 2216 ^p2 3213)
  32.     (make line ^p1 0107 ^p2 2601)
  33.     (make line ^p1 2601 ^p2 7401)
  34.     (make line ^p1 6404 ^p2 7401)
  35.     (make line ^p1 3213 ^p2 6413)
  36.     (make line ^p1 6413 ^p2 6404)
  37.     (make line ^p1 7416 ^p2 7401)
  38.     (make line ^p1 5216 ^p2 6413)
  39.     (make line ^p1 2216 ^p2 5216)
  40.     (make line ^p1 0122 ^p2 5222)
  41.     (make line ^p1 5222 ^p2 7416)
  42.     (make line ^p1 5222 ^p2 5216)
  43.     (modify 1 ^value duplicate))
  44.  
  45. ;If the duplicate flag is set, and there is still a line in WM, delete the line
  46. ;and add two edges. One edge runs from p1 to p2 and the other runs from p2 to
  47. ;p1.  We then plot the edge.
  48. (p reverse_edges
  49.     (stage ^value duplicate)
  50.     (line ^p1 <p1> ^p2 <p2>)
  51.     -->
  52. ;    (write draw <p1> <p2> (crlf))
  53.     (make edge ^p1 <p1> ^p2 <p2> ^joined false)
  54.         (make edge ^p1 <p2> ^p2 <p1> ^joined false)
  55.     (remove 2))
  56.  
  57. ;If the duplicating flag is set, and there are no more lines, then remove the
  58. ;duplicating flag and set the make junctions flag.
  59. (p done_reversing
  60.     (stage ^value duplicate)
  61.     - (line)
  62.     -->
  63.     (modify 1 ^value detect_junctions))
  64.  
  65.  
  66. ;If three edges meet at a point and none of them have already been joined in
  67. ;a junction, then make the corresponding type of junction and label the
  68. ;edges joined.  This production calls make-3_junction to determine
  69. ;what type of junction it is based on the angles inscribed by the
  70. ;intersecting edges
  71. (p make-3_junction
  72.     (stage ^value detect_junctions)
  73.     (edge ^p1 <base_point> ^p2 <p1> ^joined false)
  74.     (edge ^p1 <base_point> ^p2 {<p2> <> <p1>} ^joined false)
  75.     (edge ^p1 <base_point> ^p2 {<p3> <> <p1> <> <p2>} ^joined false)
  76.     -->
  77.     (make junction
  78.           ^type (make_3_junction <base_point> <p1> <p2> <p3>)
  79.               ^base_point <base_point>)
  80.     (modify 2 ^joined true)
  81.     (modify 3 ^joined true)
  82.     (modify 4 ^joined true))
  83.  
  84. ;If two, and only two, edges meet that have not already been joined, then
  85. ;the junction is an "L"
  86. (p make_L
  87.     (stage ^value detect_junctions)
  88.     (edge ^p1 <base_point> ^p2 <p2> ^joined false)
  89.     (edge ^p1 <base_point> ^p2 {<p3> <> <p2>} ^joined false)
  90.     - (edge ^p1 <base_point> ^p2 {<> <p2> <> <p3>})
  91.     -->
  92.     (make junction
  93.         ^type L
  94.         ^base_point <base_point>
  95.         ^p1 <p2>
  96.         ^p2 <p3>)
  97.     (modify 2 ^joined true)
  98.     (modify 3 ^joined true))
  99.  
  100.  
  101. ;If the detect junctions flag is set, and there are no more un_joined edges,
  102. ;set the find_initial_boundary flag
  103. (p done_detecting
  104.     (stage ^value detect_junctions)
  105.     - (edge ^joined false)
  106.     -->
  107.     (modify 1 ^value find_initial_boundary))
  108.  
  109. ;If the initial boundary junction is an L, then we know it's labelling
  110. (p initial_boundary_junction_L
  111.     (stage ^value find_initial_boundary)
  112.         (junction ^type L ^base_point <base_point> ^p1 <p1> ^p2 <p2>)
  113.     (edge ^p1 <base_point> ^p2 <p1>)
  114.     (edge ^p1 <base_point> ^p2 <p2>)
  115.         - (junction ^base_point > <base_point>)
  116.     -->
  117.         (modify 3 ^label B)
  118.     (modify 4 ^label B)
  119.     (modify 1 ^value find_second_boundary))
  120.  
  121. ;Ditto for an arrow
  122. (p initial_boundary_junction_arrow
  123.     (stage ^value find_initial_boundary)
  124.     (junction ^type arrow ^base_point <bp> ^p1 <p1> ^p2 <p2> ^p3 <p3>)
  125.     (edge ^p1 <bp> ^p2 <p1>)
  126.     (edge ^p1 <bp> ^p2 <p2>)
  127.     (edge ^p1 <bp> ^p2 <p3>)
  128.     - (junction ^base_point > <bp>)
  129.     -->
  130.     (modify 3 ^label B)
  131.     (modify 4 ^label +)
  132.     (modify 5 ^label B)
  133.     (modify 1 ^value find_second_boundary))
  134.  
  135. ;If we have already found the first boundary point, then find the second
  136. ;boundary point, and label it.
  137.  
  138. (p second_boundary_junction_L
  139.     (stage ^value find_second_boundary)
  140.         (junction ^type L ^base_point <base_point> ^p1 <p1> ^p2 <p2>)
  141.     (edge ^p1 <base_point> ^p2 <p1>)
  142.     (edge ^p1 <base_point> ^p2 <p2>)
  143.         - (junction ^base_point < <base_point>)
  144.     -->
  145.         (modify 3 ^label B)
  146.     (modify 4 ^label B)
  147.     (modify 1 ^value labeling))
  148.  
  149. (p second_boundary_junction_arrow
  150.     (stage ^value find_second_boundary)
  151.     (junction ^type arrow ^base_point <bp> ^p1 <p1> ^p2 <p2> ^p3 <p3>)
  152.     (edge ^p1 <bp> ^p2 <p1>)
  153.     (edge ^p1 <bp> ^p2 <p2>)
  154.     (edge ^p1 <bp> ^p2 <p3>)
  155.     - (junction ^base_point < <bp>)
  156.     -->
  157.     (modify 3 ^label B)
  158.     (modify 4 ^label +)
  159.     (modify 5 ^label B)
  160.     (modify 1 ^value labeling))
  161.  
  162.  
  163. ;If we have an edge whose label we already know definitely, then
  164. ;label the corresponding edge in the other direction
  165. (p match_edge
  166.     (stage ^value labeling)
  167.     (edge ^p1 <p1> ^p2 <p2> ^label {<label> << + - B >>})
  168.     (edge ^p1 <p2> ^p2 <p1> ^label nil)
  169.     -->
  170.     (modify 2 ^plotted t)
  171.     (modify 3 ^label <label> ^plotted t)
  172. ;    (write plot <label> <p1> <p2> (crlf))
  173.     ) 
  174. ;The following productions propogate the possible labellings of the edges
  175. ;based on the labellings of edges incident on adjacent junctions.  Since
  176. ;from the initial boundary productions, we have determined the labellings of
  177. ;of atleast two junctions, this propogation will label all of the junctions
  178. ;with the possible labellings.  The search space is pruned due to filtering,
  179. ;i.e. - only label a junction in the ways physically possible based on the
  180. ;labellings of adjacent junctions.
  181.  
  182.  
  183. (p label_L
  184.     (stage ^value labeling)
  185.     (junction ^type L ^base_point <p1>)
  186.     (edge ^p1 <p1> ^p2 <p2> ^label << + - >>)
  187.     (edge ^p1 <p1> ^p2 <> <p2> ^label nil)
  188.     -->
  189.     (modify 4 ^label B))
  190.  
  191.  
  192. (p label_tee_A
  193.     (stage ^value labeling)
  194.     (junction ^type tee ^base_point <bp> ^p1 <p1> ^p2 <p2> ^p3 <p3>)
  195.     (edge ^p1 <bp> ^p2 <p1> ^label nil)
  196.     (edge ^p1 <bp> ^p2 <p3>)
  197.     -->
  198.     (modify 3 ^label B)
  199.     (modify 4 ^label B))
  200.  
  201.  
  202. (p label_tee_B
  203.     (stage ^value labeling)
  204.     (junction ^type tee ^base_point <bp> ^p1 <p1> ^p2 <p2> ^p3 <p3>)
  205.     (edge ^p1 <bp> ^p2 <p1>)
  206.     (edge ^p1 <bp> ^p2 <p3> ^label nil)
  207.     -->
  208.     (modify 3 ^label B)
  209.     (modify 4 ^label B))
  210.  
  211.  
  212. (p label_fork-1
  213.     (stage ^value labeling)
  214.     (junction ^type fork ^base_point <bp>)
  215.     (edge ^p1 <bp> ^p2 <p1> ^label +)
  216.     (edge ^p1 <bp> ^p2 {<p2> <> <p1>} ^label nil)
  217.     (edge ^p1 <bp> ^p2 {<> <p2> <> <p1>})
  218.     -->
  219.     (modify 4 ^label +)
  220.     (modify 5 ^label +))
  221.  
  222.  
  223. (p label_fork-2
  224.     (stage ^value labeling)
  225.     (junction ^type fork ^base_point <bp>)
  226.     (edge ^p1 <bp> ^p2 <p1> ^label B)
  227.     (edge ^p1 <bp> ^p2 {<p2> <> <p1>} ^label -)
  228.     (edge ^p1 <bp> ^p2 {<> <p2> <> <p1>} ^label nil)
  229.     -->
  230.     (modify 5 ^label B))
  231.  
  232.  
  233. (p label_fork-3
  234.     (stage ^value labeling)
  235.     (junction ^type fork ^base_point <bp>)
  236.     (edge ^p1 <bp> ^p2 <p1> ^label B)
  237.     (edge ^p1 <bp> ^p2 {<p2> <> <p1>} ^label B)
  238.     (edge ^p1 <bp> ^p2 {<> <p2> <> <p1>} ^label nil)
  239.     -->
  240.     (modify 5 ^label -))
  241.  
  242.  
  243. (p label_fork-4
  244.     (stage ^value labeling)
  245.     (junction ^type fork ^base_point <bp>)
  246.     (edge ^p1 <bp> ^p2 <p1> ^label -)
  247.     (edge ^p1 <bp> ^p2 {<p2> <> <p1>} ^label -)
  248.     (edge ^p1 <bp> ^p2 {<> <p2> <> <p1>} ^label nil)
  249.     -->
  250.     (modify 5 ^label -))
  251.  
  252.  
  253.  
  254. (p label_arrow-1A
  255.     (stage ^value labeling)
  256.     (junction ^type arrow ^base_point <bp> ^p1 <p1> ^p2 <p2> ^p3 <p3>)
  257.     (edge ^p1 <bp> ^p2 <p1> ^label {<label> << B - >>})
  258.     (edge ^p1 <bp> ^p2 <p2> ^label nil)
  259.     (edge ^p1 <bp> ^p2 <p3>)
  260.     -->
  261.     (modify 4 ^label +)
  262.     (modify 5 ^label <label>))
  263.  
  264.  
  265. (p label_arrow-1B
  266.     (stage ^value labeling)
  267.     (junction ^type arrow ^base_point <bp> ^p1 <p1> ^p2 <p2> ^p3 <p3>)
  268.     (edge ^p1 <bp> ^p2 <p1> ^label {<label> << B - >>})
  269.     (edge ^p1 <bp> ^p2 <p2>)
  270.     (edge ^p1 <bp> ^p2 <p3> ^label nil)
  271.     -->
  272.     (modify 4 ^label +)
  273.     (modify 5 ^label <label>))
  274.  
  275.  
  276. (p label_arrow-2A
  277.     (stage ^value labeling)
  278.     (junction ^type arrow ^base_point <bp> ^p1 <p1> ^p2 <p2> ^p3 <p3>)
  279.     (edge ^p1 <bp> ^p2 <p3> ^label {<label> << B - >>})
  280.     (edge ^p1 <bp> ^p2 <p2> ^label nil)
  281.     (edge ^p1 <bp> ^p2 <p1>)
  282.     -->
  283.     (modify 4 ^label +)
  284.     (modify 5 ^label <label>))
  285.  
  286. (p label_arrow-2B
  287.     (stage ^value labeling)
  288.     (junction ^type arrow ^base_point <bp> ^p1 <p1> ^p2 <p2> ^p3 <p3>)
  289.     (edge ^p1 <bp> ^p2 <p3> ^label {<label> << B - >>})
  290.     (edge ^p1 <bp> ^p2 <p2>)
  291.     (edge ^p1 <bp> ^p2 <p1> ^label nil)
  292.     -->
  293.     (modify 4 ^label +)
  294.     (modify 5 ^label <label>))
  295.  
  296.  
  297. (p label_arrow-3A
  298.     (stage ^value labeling)
  299.     (junction ^type arrow ^base_point <bp> ^p1 <p1> ^p2 <p2> ^p3 <p3>)
  300.     (edge ^p1 <bp> ^p2 <p1> ^label +)
  301.     (edge ^p1 <bp> ^p2 <p2> ^label nil)
  302.     (edge ^p1 <bp> ^p2 <p3>)
  303.     -->
  304.     (modify 4 ^label -)
  305.     (modify 5 ^label +))
  306.  
  307. (p label_arrow-3B
  308.     (stage ^value labeling)
  309.     (junction ^type arrow ^base_point <bp> ^p1 <p1> ^p2 <p2> ^p3 <p3>)
  310.     (edge ^p1 <bp> ^p2 <p1> ^label +)
  311.     (edge ^p1 <bp> ^p2 <p2>)
  312.     (edge ^p1 <bp> ^p2 <p3> ^label nil)
  313.     -->
  314.     (modify 4 ^label -)
  315.     (modify 5 ^label +))
  316.  
  317.  
  318. (p label_arrow-4A
  319.     (stage ^value labeling)
  320.     (junction ^type arrow ^base_point <bp> ^p1 <p1> ^p2 <p2> ^p3 <p3>)
  321.     (edge ^p1 <bp> ^p2 <p3> ^label +)
  322.     (edge ^p1 <bp> ^p2 <p2> ^label nil)
  323.     (edge ^p1 <bp> ^p2 <p1>)
  324.     -->
  325.     (modify 4 ^label -)
  326.     (modify 5 ^label +))
  327.  
  328. (p label_arrow-4B
  329.     (stage ^value labeling)
  330.     (junction ^type arrow ^base_point <bp> ^p1 <p1> ^p2 <p2> ^p3 <p3>)
  331.     (edge ^p1 <bp> ^p2 <p3> ^label +)
  332.     (edge ^p1 <bp> ^p2 <p2>)
  333.     (edge ^p1 <bp> ^p2 <p1> ^label nil)
  334.     -->
  335.     (modify 4 ^label -)
  336.     (modify 5 ^label +))
  337.  
  338.  
  339. (p label_arrow-5A
  340.     (stage ^value labeling)
  341.     (junction ^type arrow ^base_point <bp> ^p1 <p1> ^p2 <p2> ^p3 <p3>)
  342.     (edge ^p1 <bp> ^p2 <p2> ^label -)
  343.     (edge ^p1 <bp> ^p2 <p1>)
  344.     (edge ^p1 <bp> ^p2 <p3> ^label nil)
  345.     -->
  346.     (modify 4 ^label +)
  347.     (modify 5 ^label +))
  348.  
  349.  
  350. (p label_arrow-5B
  351.     (stage ^value labeling)
  352.     (junction ^type arrow ^base_point <bp> ^p1 <p1> ^p2 <p2> ^p3 <p3>)
  353.     (edge ^p1 <bp> ^p2 <p2> ^label -)
  354.     (edge ^p1 <bp> ^p2 <p1> ^label nil)
  355.     (edge ^p1 <bp> ^p2 <p3>)
  356.     -->
  357.     (modify 4 ^label +)
  358.     (modify 5 ^label +))
  359.  
  360.  
  361. ;The conflict resolution mechanism will onle execute a production if no
  362. ;productions that are more complicated are satisfied.  This production is
  363. ;simple, so all of the above dictionary productions will fire before this
  364. ;change of state production
  365. (p done_labeling
  366.     (stage ^value labeling)
  367.     -->
  368.     (modify 1 ^value plot_remaining_edges))
  369.  
  370. ;At this point, some labellings may have not been plotted, so plot them
  371. (p plot_remaining
  372.     (stage ^value plot_remaining_edges)
  373.     (edge ^plotted nil ^label {<label> <> nil} ^p1 <p1> ^p2 <p2>)
  374.     -->
  375. ;    (write plot <label> <p1> <p2> (crlf))
  376.     (modify 2 ^plotted t))
  377.  
  378.  
  379. ;If we have been un able to label an edge, assume that it is a boundary.
  380. ;This is a total Kludge, but what the hell. (if we assume only valid drawings
  381. ;will be given for labeling, this assumption generally is true!)
  382. (p plot_boundaries
  383.     (stage ^value plot_remaining_edges)
  384.     (edge ^plotted nil ^label nil ^p1 <p1> ^p2 <p2>)
  385.     -->
  386. ;    (write plot B <p1> <p2> (crlf))
  387.     (modify 2 ^plotted t))
  388.  
  389. ;If there is no more work to do, then we are done and flag it.
  390. (p done_plotting
  391.     (stage ^value plot_remaining_edges)
  392.     - (edge ^plotted nil)
  393.     -->
  394.     (modify 1 ^value done))
  395.  
  396. ;Prompt the user as to where he can see a trace of the OPS5
  397. ;execution
  398. (p done
  399.     (stage ^value done)
  400.     -->
  401. ;    (write see trace.waltz for description of execution- hit CR to end (crlf))
  402.     (halt))
  403.